import java.io.*;


public class TSP_GA {
	public static void main(String[] args) throws Exception {
		long start=System.currentTimeMillis();
		BufferedReader br = new BufferedReader(new FileReader("file.txt"));
        String line;
        while((line = br.readLine())!= null)
        {
            String[]numbers = line.split(",");
            int[]nums = new int[numbers.length];
            for (int i = 0; i < nums.length; i++) {
                nums[i] = Integer.parseInt(numbers[i]);
            }
           
            City city = new City(nums[0],nums[1]);
            TourManager.addCity(city);
        
        }
        
           br.close();
            
        // Create and add our cities
       
        
             
        // Initialize population
        Population pop = new Population(50, true);
        System.out.println("Initial distance: " + pop.getFittest().getDistance());

        // Evolve population for 50 generations
        pop = GA.evolvePopulation(pop);
        for (int i = 0; i < 100; i++) {
            pop = GA.evolvePopulation(pop);
        }

        // Print final results
        System.out.println("Finished");
        System.out.println("Final distance: " + pop.getFittest().getDistance());
        System.out.println("Solution:");
        System.out.println(pop.getFittest());
        long stop=System.currentTimeMillis();
        long elapsed=stop-start;
        System.out.println("time taken in millseconds: "+ elapsed);
	}
}
